package com.sec.android.app.myfiles.module.local.category;

import android.content.Context;

import com.sec.android.app.myfiles.facade.FacadeItem;
import com.sec.android.app.myfiles.fragment.AbsMyFilesFragment;
import com.sec.android.app.myfiles.fragment.home.HomeFragment;
import com.sec.android.app.myfiles.fragment.home.HomeFragmentItem;
import com.sec.android.app.myfiles.module.ContentObservable;
import com.sec.android.app.myfiles.module.abstraction.AbsContentObserverImp;
import com.sec.android.app.myfiles.module.abstraction.AbsDragAndDrop;
import com.sec.android.app.myfiles.module.abstraction.AbsFileListAdapterImp;
import com.sec.android.app.myfiles.module.abstraction.AbsFileOperationImp;
import com.sec.android.app.myfiles.module.abstraction.AbsMenuImp;
import com.sec.android.app.myfiles.module.abstraction.AbsModuleLoaderImp;
import com.sec.android.app.myfiles.module.abstraction.AbsProviderImp;
import com.sec.android.app.myfiles.module.abstraction.AbsReloadStrategyImp;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.module.abstraction.FileRecord.StorageType;
import com.sec.android.app.myfiles.module.local.category.audio.AudioListAdapterImp;
import com.sec.android.app.myfiles.module.local.category.folder.FolderListAdapterImp;
import com.sec.android.app.myfiles.navigation.NavigationInfo;
import com.sec.android.app.myfiles.navigation.NavigationInfo.NavigationMode;
import com.sec.android.app.myfiles.operation.ProgressListener;
import com.sec.android.app.myfiles.provider.DbTableInfo;
import com.sec.android.app.myfiles.widget.listview.AbsListViewImp;

import java.util.ArrayList;

public class CategoryModuleLoaderImp extends AbsModuleLoaderImp {

    @Override
    protected StorageType getSupportStorage() {
        return StorageType.Category;
    }

    @Override
    protected FileRecord _createFileRecord(String fullPath) {
        return new CategoryFileRecord(fullPath);
    }

    @Override
    protected FileRecord _createFileRecord(int id, String path, String name, long size, long date, int fileType, int isHidden, int itemCount,
                                           int itemCountHidden) {
        return new CategoryFileRecord(id, path, name, size, date, fileType, isHidden, itemCount, itemCountHidden);
    }

    @Override
    public AbsFileListAdapterImp _createAdapterImp(Context context, NavigationInfo navigationInfo, AbsListViewImp listView) {
        AbsFileListAdapterImp ret;
        CategoryFileRecord record = (CategoryFileRecord) navigationInfo.getCurRecord();

        if (record.getBucketId() == null && record.getCategoryType() != FileRecord.CategoryType.None) {
            ret = new FolderListAdapterImp(context, navigationInfo, listView, null, 0);
        } else if (record.getCategoryType() == FileRecord.CategoryType.Audio) {
            ret = new AudioListAdapterImp(context, navigationInfo, listView, null, 0);
        } else {
            ret = new CategoryListAdapterImp(context, navigationInfo, listView, null, 0);
        }
        return ret;
    }

    @Override
    public AbsProviderImp _createProviderImp(Context context) {
        AbsProviderImp ret = new CategoryProviderImp(context);
        return ret;
    }

    @Override
    public DbTableInfo _getTableInfoImp() {
        return CategoryDbTableInfo.getInstance();
    }

    @Override
    public AbsMenuImp _createMenuImp(Context context, StorageType supportStorage) {
        AbsMenuImp ret = new CategoryMenuImp(context, supportStorage);
        return ret;
    }

    @Override
    protected AbsFileOperationImp _createFileOperationImp(Context context, ProgressListener listener) {
        return null;
    }

    @Override
    protected void _createHomeItem(Context context, HomeFragment fragment, ArrayList<HomeFragmentItem> itemList, boolean isLeftPanel) {
        NavigationInfo info = fragment.getNavigationInfo();
        if (info != null) {
            HomeFragmentItem item = null;

            if (info.getNavigationMode() == NavigationMode.Normal) {
                if (isLeftPanel) {
                    item = new ListCategoryHomeItem(context, fragment);
                } else {
                    item = new CategoryHomeItem(context, fragment);
                }
            } else if (info.getNavigationMode() == NavigationMode.Pick_files) {
                item = new PickerCategoryHomeItem(context, fragment);
            }
            itemList.add(item);
        }
    }

    @Override
    protected void _addFacadeItemList(ArrayList<FacadeItem> facadeItem) {
    }

    @Override
    protected AbsContentObserverImp _createContentObserver(Context context, FileRecord record, ContentObservable updater) {
        return new CategoryContentObserverImp(context, record, updater);
    }

    @Override
    protected AbsReloadStrategyImp _createReloadStrategy(Context context, NavigationInfo navigationInfo) {
        return new CategoryReloadStrategyImp(context, navigationInfo);
    }

    @Override
    protected AbsDragAndDrop _getDragAndDropImp(AbsMyFilesFragment fragment, AbsListViewImp listViewImp) {
        return new CategoryDragAndDropImp(fragment, listViewImp);
    }

}
